let tempPkId = ''
let tempTaskName = ''
export default (api, form, rule, value, callback) => {
  // console.log('请求api',api)
  // console.log('表单',form)
  if (value === '' || value === null || value === undefined) {
    callback(new Error('请输入任务名称'))
  } else {
    if (form.pkId) {
      if (tempPkId !== form.pkId) {
        tempPkId = form.pkId
      }
      tempTaskName = form.validateName
    }
    const params = {
      taskName: value,
      size: 500000
    }
    api.findListByPage(params).then(rsp => {
      if (rsp.total > 0) {
        const isExist = rsp.content.some(item => item.taskName === value)
        // console.log('任务值', tempTaskName)
        if (isExist && tempTaskName !== value) {
          callback(new Error('任务名称已存在！'))
        } else {
          callback()
        }
      } else {
        callback()
      }
    })
  }
}
